# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# Author     ：skyTree
# version    ：python 3.11
# Description：角色序列化器
"""
from rest_framework.serializers import ModelSerializer, ListField
from rest_framework.relations import PrimaryKeyRelatedField
from roles.models import Role
from menu.models import Menu


class RoleSerializer(ModelSerializer):
    menus = PrimaryKeyRelatedField(many=True, queryset=Menu.objects.all(), help_text='菜单', required=False,
                                   write_only=True)
    menus_list = ListField(read_only=True)
    menus_tree_list = ListField(read_only=True)

    class Meta:
        model = Role
        fields = '__all__'
